package com.spring.component.rabbitmq;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import com.spring.component.utils.StringUtil;

/**
 * 多rabbitmq环境配置
 * 
 * @author liushihua
 * @since 2018年04月11日
 */
@Component
public class Properties {
  // 默认rabbitmq配置
  private String host;
  private String port;
  private String username;
  private String password;
  private String virtualHost;
  private String queues;
  private String topics;
  private String routing;
  private String exchange;
  private String iotbusHost;
  // 自定义rabbitmq配置
  private String iotbusPort;
  private String iotbusUsername;
  private String iotbusPassword;
  private String iotbusVirtualHost;
  private String iotbusQueues;
  private String iotbusTopics;
  private String iotbusRouting;
  private String iotbusExchange;
  // 日志rabbitmq配置
  private String logHost;
  private String logPort;
  private String logUsername;
  private String logPassword;
  private String logVirtualHost;
  private String logQueues;
  private String logEnable;

  @Autowired
  private Environment env;
  public static final String TOPIC_EXCHANGE = "TOPIC.EXCHANGE";

  @Bean(name = "rabbitProperties")
  public Properties properties() {
    Properties properties = new Properties();
    this.host = this.env.getProperty("spring.rabbitmq.host", "");
    this.port = this.env.getProperty("spring.rabbitmq.port", "");
    this.username = this.env.getProperty("spring.rabbitmq.username", "");
    this.password = this.env.getProperty("spring.rabbitmq.password", "");
    this.virtualHost = this.env.getProperty("spring.rabbitmq.virtualHost", "");
    this.queues = this.env.getProperty("spring.rabbitmq.queues", "");
    this.topics = this.env.getProperty("spring.rabbitmq.topics", "");
    this.routing = this.env.getProperty("spring.rabbitmq.topic.routing", "");
    this.exchange = this.env.getProperty("spring.rabbitmq.topic.exchange", "true");
    this.iotbusHost = this.env.getProperty("iotbus.rabbitmq.host", "");
    this.iotbusPort = this.env.getProperty("iotbus.rabbitmq.port", "");
    this.iotbusUsername = this.env.getProperty("iotbus.rabbitmq.username", "");
    this.iotbusPassword = this.env.getProperty("iotbus.rabbitmq.password", "");
    this.iotbusVirtualHost = this.env.getProperty("iotbus.rabbitmq.virtualHost", "");
    this.iotbusQueues = this.env.getProperty("iotbus.rabbitmq.queues", "");
    this.iotbusTopics = this.env.getProperty("iotbus.rabbitmq.topics", "");
    this.iotbusRouting = this.env.getProperty("iotbus.rabbitmq.topic.routing", "");
    this.iotbusExchange = this.env.getProperty("iotbus.rabbitmq.topic.exchange", "true");
    this.logHost = this.env.getProperty("log.rabbitmq.host", "");
    this.logPort = this.env.getProperty("log.rabbitmq.port", "");
    this.logUsername = this.env.getProperty("log.rabbitmq.username", "");
    this.logPassword = this.env.getProperty("log.rabbitmq.password", "");
    this.logVirtualHost = this.env.getProperty("log.rabbitmq.virtualHost", "");
    this.logQueues = this.env.getProperty("log.rabbitmq.queues", "");
    this.logEnable = this.env.getProperty("log.enable", "");
    properties.setHost(this.host);
    properties.setPort(this.port);
    properties.setUsername(this.username);
    properties.setPassword(this.password);
    properties.setVirtualHost(this.virtualHost);
    properties.setQueues(this.queues);
    properties.setTopics(this.topics);
    properties.setRouting(this.routing);
    properties.setExchange(this.exchange);
    properties.setIotbusHost(this.iotbusHost);
    properties.setIotbusPort(this.iotbusPort);
    properties.setIotbusUsername(this.iotbusUsername);
    properties.setIotbusPassword(this.iotbusPassword);
    properties.setIotbusVirtualHost(this.iotbusVirtualHost);
    properties.setIotbusQueues(this.iotbusQueues);
    properties.setIotbusTopics(this.iotbusTopics);
    properties.setIotbusRouting(this.iotbusRouting);
    properties.setIotbusExchange(this.iotbusExchange);
    properties.setLogHost(this.logHost);
    properties.setLogPort(this.logPort);
    properties.setLogUsername(this.logUsername);
    properties.setLogPassword(this.logPassword);
    properties.setLogVirtualHost(this.logVirtualHost);
    properties.setLogQueues(this.logQueues);
    properties.setLogEnable(this.logEnable);
    return properties;
  }

  public boolean validQueue() {
    return StringUtil.isNumeric(this.port)
        && StringUtil.isAllNotBlank(this.host, this.username, this.password);
  }

  public boolean validIotbusQueue() {
    return StringUtil.isNumeric(this.iotbusPort)
        && StringUtil.isAllNotBlank(this.iotbusHost, this.iotbusUsername, this.iotbusPassword);
  }

  public boolean validLogQueue() {
    return StringUtil.isNumeric(this.logPort)
        && StringUtil.isAllNotBlank(this.logHost, this.logUsername, this.logPassword);
  }

  public String getHost() {
    return host;
  }

  public void setHost(String host) {
    this.host = host;
  }

  public String getPort() {
    return port;
  }

  public void setPort(String port) {
    this.port = port;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getVirtualHost() {
    return virtualHost;
  }

  public void setVirtualHost(String virtualHost) {
    this.virtualHost = virtualHost;
  }

  public String getQueues() {
    return queues;
  }

  public void setQueues(String queues) {
    this.queues = queues;
  }

  public String getTopics() {
    return topics;
  }

  public void setTopics(String topics) {
    this.topics = topics;
  }

  public String getRouting() {
    return routing;
  }

  public void setRouting(String routing) {
    this.routing = routing;
  }

  public String getExchange() {
    return exchange;
  }

  public void setExchange(String exchange) {
    this.exchange = exchange;
  }

  public String getIotbusHost() {
    return iotbusHost;
  }

  public void setIotbusHost(String iotbusHost) {
    this.iotbusHost = iotbusHost;
  }

  public String getIotbusPort() {
    return iotbusPort;
  }

  public void setIotbusPort(String iotbusPort) {
    this.iotbusPort = iotbusPort;
  }

  public String getIotbusUsername() {
    return iotbusUsername;
  }

  public void setIotbusUsername(String iotbusUsername) {
    this.iotbusUsername = iotbusUsername;
  }

  public String getIotbusPassword() {
    return iotbusPassword;
  }

  public void setIotbusPassword(String iotbusPassword) {
    this.iotbusPassword = iotbusPassword;
  }

  public String getIotbusVirtualHost() {
    return iotbusVirtualHost;
  }

  public void setIotbusVirtualHost(String iotbusVirtualHost) {
    this.iotbusVirtualHost = iotbusVirtualHost;
  }

  public String getIotbusQueues() {
    return iotbusQueues;
  }

  public void setIotbusQueues(String iotbusQueues) {
    this.iotbusQueues = iotbusQueues;
  }

  public String getIotbusTopics() {
    return iotbusTopics;
  }

  public void setIotbusTopics(String iotbusTopics) {
    this.iotbusTopics = iotbusTopics;
  }

  public String getIotbusRouting() {
    return iotbusRouting;
  }

  public void setIotbusRouting(String iotbusRouting) {
    this.iotbusRouting = iotbusRouting;
  }

  public String getIotbusExchange() {
    return iotbusExchange;
  }

  public void setIotbusExchange(String iotbusExchange) {
    this.iotbusExchange = iotbusExchange;
  }

  public String getLogHost() {
    return logHost;
  }

  public void setLogHost(String logHost) {
    this.logHost = logHost;
  }

  public String getLogPort() {
    return logPort;
  }

  public void setLogPort(String logPort) {
    this.logPort = logPort;
  }

  public String getLogUsername() {
    return logUsername;
  }

  public void setLogUsername(String logUsername) {
    this.logUsername = logUsername;
  }

  public String getLogPassword() {
    return logPassword;
  }

  public void setLogPassword(String logPassword) {
    this.logPassword = logPassword;
  }

  public String getLogVirtualHost() {
    return logVirtualHost;
  }

  public void setLogVirtualHost(String logVirtualHost) {
    this.logVirtualHost = logVirtualHost;
  }

  public String getLogQueues() {
    return logQueues;
  }

  public void setLogQueues(String logQueues) {
    this.logQueues = logQueues;
  }

  public String getLogEnable() {
    return logEnable;
  }

  public void setLogEnable(String logEnable) {
    this.logEnable = logEnable;
  }
}
